package com.itheima.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/channel")
@Api(tags ="频道管理")
public class AdchannelController {

    @Autowired
    private AdChannelService adChannelService;

    @ApiOperation("频道分页查询")
    @PostMapping("/list")
    public PageResultVo pageResult(@RequestBody @Validated ChannelPageRequestDto dto){
        PageResultVo vo =adChannelService.findPage(dto);
        return vo;
    }

    @PostMapping("/save")
    @ApiOperation("新增频道")
    public ResultVo add(@RequestBody AdChannel adChannel){
        adChannelService.add(adChannel);
        return ResultVo.ok();
    }

    @GetMapping("/{channelId}")
    @ApiOperation("ip查询")
    public ResultVo findById(@PathVariable(value = "channelId")Integer channelId){
        AdChannel adChannel = adChannelService.getById(channelId);
        return ResultVo.ok(adChannel);
    }
    @PostMapping("/update")
    @ApiOperation("更新")
    public ResultVo  update(@RequestBody AdChannel adChannel){
        adChannelService.updateById(adChannel);
        return ResultVo.ok();

    }
    @DeleteMapping("/{adChannelId}")
    @ApiOperation("删除")
    public ResultVo deleteid(@PathVariable(value = "adChannelId")Integer adChannelId){
        adChannelService.removeById(adChannelId);
        return ResultVo.ok();


    }
    

}
